from typing import *


class Solution:
    def countBadPairs(self, nums: List[int]) -> int:
        cnt = DefaultDict(int)
        ans = 0
        for i, v in enumerate(nums):
            ans += i - cnt[i - v]
            cnt[i - v] += 1
        return ans
